package o;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.bumptech.glide.Registry.NoModelLoaderAvailableException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import o.vk.c;

public class vo {
    private static final e ˎ = new e();
    private static final vk<Object, Object> ॱ = new a();
    private final e ˊ;
    private final List<d<?, ?>> ˋ;
    private final Set<d<?, ?>> ˏ;
    private final o.hg.e<List<Throwable>> ॱॱ;

    static class a implements vk<Object, Object> {
        a() {
        }

        @Nullable
        public c<Object> ˎ(@NonNull Object obj, int i, int i2, @NonNull sc scVar) {
            return null;
        }

        public boolean ˋ(@NonNull Object obj) {
            return false;
        }
    }

    static class d<Model, Data> {
        final vr<? extends Model, ? extends Data> ˋ;
        private final Class<Model> ˏ;
        final Class<Data> ॱ;

        public d(@NonNull Class<Model> cls, @NonNull Class<Data> cls2, @NonNull vr<? extends Model, ? extends Data> vrVar) {
            this.ˏ = cls;
            this.ॱ = cls2;
            this.ˋ = vrVar;
        }

        public boolean ˋ(@NonNull Class<?> cls, @NonNull Class<?> cls2) {
            return ˊ(cls) && this.ॱ.isAssignableFrom(cls2);
        }

        public boolean ˊ(@NonNull Class<?> cls) {
            return this.ˏ.isAssignableFrom(cls);
        }
    }

    static class e {
        e() {
        }

        @NonNull
        public <Model, Data> vp<Model, Data> ˊ(@NonNull List<vk<Model, Data>> list, @NonNull o.hg.e<List<Throwable>> eVar) {
            return new vp(list, eVar);
        }
    }

    public vo(@NonNull o.hg.e<List<Throwable>> eVar) {
        this(eVar, ˎ);
    }

    @VisibleForTesting
    vo(@NonNull o.hg.e<List<Throwable>> eVar, @NonNull e eVar2) {
        this.ˋ = new ArrayList();
        this.ˏ = new HashSet();
        this.ॱॱ = eVar;
        this.ˊ = eVar2;
    }

    synchronized <Model, Data> void ˏ(@NonNull Class<Model> cls, @NonNull Class<Data> cls2, @NonNull vr<? extends Model, ? extends Data> vrVar) {
        ˏ(cls, cls2, vrVar, true);
    }

    private <Model, Data> void ˏ(@NonNull Class<Model> cls, @NonNull Class<Data> cls2, @NonNull vr<? extends Model, ? extends Data> vrVar, boolean z) {
        this.ˋ.add(z ? this.ˋ.size() : 0, new d(cls, cls2, vrVar));
    }

    @NonNull
    synchronized <Model, Data> List<vr<? extends Model, ? extends Data>> ˊ(@NonNull Class<Model> cls, @NonNull Class<Data> cls2, @NonNull vr<? extends Model, ? extends Data> vrVar) {
        List<vr<? extends Model, ? extends Data>> ˋ;
        ˋ = ˋ(cls, cls2);
        ˏ(cls, cls2, vrVar);
        return ˋ;
    }

    @NonNull
    synchronized <Model, Data> List<vr<? extends Model, ? extends Data>> ˋ(@NonNull Class<Model> cls, @NonNull Class<Data> cls2) {
        List<vr<? extends Model, ? extends Data>> arrayList;
        arrayList = new ArrayList();
        Iterator it = this.ˋ.iterator();
        while (it.hasNext()) {
            d dVar = (d) it.next();
            if (dVar.ˋ(cls, cls2)) {
                it.remove();
                arrayList.add(ˎ(dVar));
            }
        }
        return arrayList;
    }

    @NonNull
    synchronized <Model> List<vk<Model, ?>> ˏ(@NonNull Class<Model> cls) {
        List<vk<Model, ?>> arrayList;
        try {
            arrayList = new ArrayList();
            for (d dVar : this.ˋ) {
                if (!this.ˏ.contains(dVar) && dVar.ˊ(cls)) {
                    this.ˏ.add(dVar);
                    arrayList.add(ˏ(dVar));
                    this.ˏ.remove(dVar);
                }
            }
        } catch (Throwable th) {
            this.ˏ.clear();
        }
        return arrayList;
    }

    @NonNull
    synchronized List<Class<?>> ˊ(@NonNull Class<?> cls) {
        List<Class<?>> arrayList;
        arrayList = new ArrayList();
        for (d dVar : this.ˋ) {
            if (!arrayList.contains(dVar.ॱ) && dVar.ˊ(cls)) {
                arrayList.add(dVar.ॱ);
            }
        }
        return arrayList;
    }

    @NonNull
    public synchronized <Model, Data> vk<Model, Data> ˊ(@NonNull Class<Model> cls, @NonNull Class<Data> cls2) {
        vk<Model, Data> ˊ;
        try {
            List arrayList = new ArrayList();
            Object obj = null;
            for (d dVar : this.ˋ) {
                if (this.ˏ.contains(dVar)) {
                    obj = 1;
                } else if (dVar.ˋ(cls, cls2)) {
                    this.ˏ.add(dVar);
                    arrayList.add(ˏ(dVar));
                    this.ˏ.remove(dVar);
                }
            }
            if (arrayList.size() > 1) {
                ˊ = this.ˊ.ˊ(arrayList, this.ॱॱ);
            } else if (arrayList.size() == 1) {
                ˊ = (vk) arrayList.get(0);
            } else if (obj != null) {
                ˊ = ˊ();
            } else {
                throw new NoModelLoaderAvailableException(cls, cls2);
            }
        } catch (Throwable th) {
            this.ˏ.clear();
        }
        return ˊ;
    }

    @NonNull
    private <Model, Data> vr<Model, Data> ˎ(@NonNull d<?, ?> dVar) {
        return dVar.ˋ;
    }

    @NonNull
    private <Model, Data> vk<Model, Data> ˏ(@NonNull d<?, ?> dVar) {
        return (vk) aas.ˎ(dVar.ˋ.ˏ(this));
    }

    @NonNull
    private static <Model, Data> vk<Model, Data> ˊ() {
        return ॱ;
    }
}
